package thread;

import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;
import java.util.concurrent.ThreadPoolExecutor;

/**
 * @author lwmzzz
 * @version 1.0
 * @date 2021/3/11 21:13
 * @description 线程池Test
 */
public class ThreadPoolTest {
    public static void main(String[] args) {
        ExecutorService executorService = Executors.newFixedThreadPool(10);
        ThreadPoolExecutor threadPoolExecutor = (ThreadPoolExecutor) executorService;
        //适合使用runnable
        executorService.execute(new NumberThread());
        executorService.execute(new NumberThreadNew()
        );
        executorService.shutdown();
        //适合使用callable
//        Future<?> submit = executorService.submit(new NumberThread());
    }
}

class NumberThread implements Runnable {
    @Override
    public void run() {
        for (int i = 0; i < 100; i++) {
            if (i % 2 == 0) {
                System.out.println(Thread.currentThread().getName() + "正在执行 输出" + i);
            }
        }
    }
}

class NumberThreadNew implements Runnable {
    @Override
    public void run() {
        for (int i = 0; i < 100; i++) {
            if (i % 2 != 0) {
                System.out.println(Thread.currentThread().getName() + "正在执行 输出" + i);
            }
        }
    }
}